# Copyright (c) 2019 Presto Labs Pte. Ltd.
# Author: jaewon

import datetime
import logging

from absl import app

from coin.exchange.okex.kr_rest.product import OkexProduct
import experimental.prophet as prophet


def graph():
  ts = prophet.global_timestamp()
  timer_1s = prophet.timer('1s')

  product = OkexProduct.FromStr('BTC-USDT')
  feed = prophet.fastfeed_coin(product, 'Spot.Okex.v3')
  trade1 = prophet.trade(feed)

  product = OkexProduct.FromStr('ETH-USDT')
  feed = prophet.fastfeed_coin(product, 'Spot.Okex.v3')
  trade2 = prophet.trade(feed)

  add = prophet.indicator.add([trade1.price, trade2.price], window_size='5s')

  t1 = prophet.last_valid(trade1.price)
  t2 = prophet.last_valid(trade2.price)
  aggregator = prophet.scalar_value_aggregator([ts, add, t1, t2])
  return aggregator


def main(argv):
  df = prophet.run_from_fastfeed_multiprocess(graph,
                                              datetime.datetime(2019, 9, 1),
                                              datetime.datetime(2019, 9, 1, 0, 10),
                                              machine='feed-01.ap-northeast-1.aws',
                                              use_run_cache=False)
  print(df.to_string())


if __name__ == '__main__':
  logging.basicConfig(level='DEBUG')
  app.run(main)
